<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of selective</title>
  <meta name="keywords" content="selective">
  <meta name="description" content="selective(g,n,n0,d) --- selective attachment random graph">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="../index.html">matgraph</a> &gt; <a href="index.html">@graph</a> &gt; selective.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for matgraph/@graph&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>selective
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>selective(g,n,n0,d) --- selective attachment random graph</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function selective(g,n,n0,d) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> selective(g,n,n0,d) --- selective attachment random graph
 overwrite g with a random graph with a degree-d selective attachment
 graph on n vertices starting with n0 isolated vertices.

 That is, we begin with n0 isolated vertices. We then add vertices one at
 a time. Each new vertex has d edges to previous vertices in the graph.
 These d edges are drawn at random (without replacement) with the
 probability of joining to a previous vertex u proportion to d(u)+1. The
 process ends when we have n vertices.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="add.html" class="code" title="function add(g,i,j)">add</a>	add --- add edge(s) to the graph</li><li><a href="clear_edges.html" class="code" title="function clear_edges(g)">clear_edges</a>	clear_edges(g) --- delete all edges of g</li><li><a href="deg.html" class="code" title="function d = deg(g,v)">deg</a>	deg: degree of a vertex or degree sequence</li><li><a href="resize.html" class="code" title="function resize(g, n)">resize</a>	resize(g,n) --- change the number of vertices in g to n</li><li><a href="rmxy.html" class="code" title="function rmxy(g)">rmxy</a>	rmxy(g) --- erase g's embedding</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="#_sub1" class="code">function c = weighted_choice(w)</a></li></ul>
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function selective(g,n,n0,d)</a>
0002 <span class="comment">% selective(g,n,n0,d) --- selective attachment random graph</span>
0003 <span class="comment">% overwrite g with a random graph with a degree-d selective attachment</span>
0004 <span class="comment">% graph on n vertices starting with n0 isolated vertices.</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% That is, we begin with n0 isolated vertices. We then add vertices one at</span>
0007 <span class="comment">% a time. Each new vertex has d edges to previous vertices in the graph.</span>
0008 <span class="comment">% These d edges are drawn at random (without replacement) with the</span>
0009 <span class="comment">% probability of joining to a previous vertex u proportion to d(u)+1. The</span>
0010 <span class="comment">% process ends when we have n vertices.</span>
0011 
0012 <a href="clear_edges.html" class="code" title="function clear_edges(g)">clear_edges</a>(g);
0013 <a href="resize.html" class="code" title="function resize(g, n)">resize</a>(g,n);
0014 <a href="rmxy.html" class="code" title="function rmxy(g)">rmxy</a>(g);
0015 
0016 <span class="keyword">for</span> v=n0+1:n
0017     wt = <a href="deg.html" class="code" title="function d = deg(g,v)">deg</a>(g);
0018     wt = wt + [ones(1,v-1),zeros(1,n-v+1)];
0019     <span class="keyword">for</span> k=1:d
0020         u = <a href="#_sub1" class="code" title="subfunction c = weighted_choice(w)">weighted_choice</a>( wt);
0021         <a href="add.html" class="code" title="function add(g,i,j)">add</a>(g,v,u);
0022         wt(u) = 0;  <span class="comment">% to avoid repetition</span>
0023     <span class="keyword">end</span>
0024 <span class="keyword">end</span>
0025 
0026 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0027 
0028 
0029 <a name="_sub1" href="#_subfunctions" class="code">function c = weighted_choice(w)</a>
0030 <span class="comment">% weighted_choice(w) --- choose an integer at random according to weights.</span>
0031 <span class="comment">% w is a list of nonnegative real values</span>
0032 <span class="comment">% return an integer c between 1 and length(w) with probability proportional</span>
0033 <span class="comment">% to w(c).</span>
0034 
0035 n = length(w);
0036 p = cumsum(w);
0037 p = p/p(n);
0038 c = sum(p&lt;rand)+1;</pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>